﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Audio;

namespace ThisIsTheOnlyChamber
{
    class ChamberFive : Chamber
    {
        bool buttonPushed = false;
        
        public ChamberFive(Game g, string s)
            : base(g, new Vector3(0, 122, -330f), s)
        {
            //Center Platform
            platforms.Add(new NormalPlatform(new Vector3(18f, 60f, 18f)));
            platforms.Add(new NormalPlatform(new Vector3(18f, 60f, -18f)));
            platforms.Add(new NormalPlatform(new Vector3(-18f, 60f, 18f)));
            platforms.Add(new NormalPlatform(new Vector3(-18f, 60f, -18f)));

            platforms.Add(new NormalPlatform(new Vector3(-18f, 60f, -48f)));
            platforms.Add(new NormalPlatform(new Vector3(-18f, 60f, 48f)));
            platforms.Add(new NormalPlatform(new Vector3(18f, 60f, -48f)));
            platforms.Add(new NormalPlatform(new Vector3(18f, 60f, 48f)));

            //Start Platform:
            platforms.Add(new NormalPlatform(new Vector3(18f, 120f, -330f)));
            platforms.Add(new NormalPlatform(new Vector3(-18f, 120f, -330f)));
            platforms.Add(new NormalPlatform(new Vector3(18f, 120f, -294f)));
            platforms.Add(new NormalPlatform(new Vector3(-18f, 120f, -294f)));

            //End Platform:
            platforms.Add(new WinPlatform(new Vector3(0f, 0f, 360f)));
            platforms.Add(new NormalPlatform(new Vector3(18f, 0f, 330f)));
            platforms.Add(new NormalPlatform(new Vector3(-18f, 0f, 330f)));
            platforms.Add(new NormalPlatform(new Vector3(18f, 0f, 294f)));
            platforms.Add(new NormalPlatform(new Vector3(-18f, 0f, 294f)));

            //Close side
            platforms.Add(new NormalPlatform(new Vector3(-90f, 120f, -312f)));
            platforms.Add(new NormalPlatform(new Vector3(-146f, 110f, -301f)));
            platforms.Add(new NormalPlatform(new Vector3(-185f, 100f, -258f)));
            platforms.Add(new NormalPlatform(new Vector3(-201f, 90f, -199f)));
            platforms.Add(new NormalPlatform(new Vector3(-185f, 80f, -145f)));
            platforms.Add(new NormalPlatform(new Vector3(-146f, 70f, -101f)));
            platforms.Add(new NormalPlatform(new Vector3(-90f, 60f, -90f)));

            //Far side
            platforms.Add(new NormalPlatform(new Vector3(90f, 0f, 312f)));
            platforms.Add(new NormalPlatform(new Vector3(146f, 10f, 301f)));
            platforms.Add(new NormalPlatform(new Vector3(185f, 20f, 258f)));
            platforms.Add(new NormalPlatform(new Vector3(201f, 30f, 199f)));
            platforms.Add(new NormalPlatform(new Vector3(185f, 40f, 145f)));
            platforms.Add(new NormalPlatform(new Vector3(146f, 50f, 101f)));
            platforms.Add(new NormalPlatform(new Vector3(90f, 60f, 90f)));

            //Walls
            walls.Add(new NorthSouthWallPart1(new Vector3(0f, 0f, 360f)));
            walls.Add(new NorthSouthWallPart2(new Vector3(0f, 0f, 360f)));
            walls.Add(new NorthSouthWallPart3(new Vector3(0f, 0f, 360f)));
            walls.Add(new NorthSouthWallPart4(new Vector3(0f, 0f, 360f)));
            walls.Add(new EastWestWall(new Vector3(0f, 0f, -360f)));
            walls.Add(new NorthSouthWall(new Vector3(360f, 0f, 0f)));
            walls.Add(new NorthSouthWall(new Vector3(-360f, 0f, 0f)));

            //Buttons
            buttons.Add(new Button(new Vector3(0f, 61.99f, 0f)));

            //Door
            door = new Door(new Vector3(0f, 96f, 346f));
        }

        protected override void LoadContent()
        {
            NormalPlatform.LoadModel(Game.Content.Load<Model>("Platform"));
            WinPlatform.LoadModel(Game.Content.Load<Model>("WinPlatform"));
            NorthSouthWall.LoadModel(Game.Content.Load<Model>("AWall"));
            NorthSouthWallPart1.LoadModel(Game.Content.Load<Model>("AWallPart1"));
            NorthSouthWallPart2.LoadModel(Game.Content.Load<Model>("AWallPart2"));
            NorthSouthWallPart3.LoadModel(Game.Content.Load<Model>("AWallPart3"));
            NorthSouthWallPart4.LoadModel(Game.Content.Load<Model>("AWallPart4"));
            EastWestWall.LoadModel(Game.Content.Load<Model>("TheOtherWall"));
            Button.LoadModel(Game.Content.Load<Model>("Button"));
            Door.LoadModel(Game.Content.Load<Model>("Door"));

            //Sounds
            ButtonSound = Game.Content.Load<SoundEffect>("buttonSound");
            DoorOpenSound = Game.Content.Load<SoundEffect>("doorOpenSound");
        }

        public override void Update(GameTime gameTime)
        {
            player.MoveUp(player.verticalVelocity * (float)gameTime.ElapsedGameTime.TotalSeconds);
            player.verticalVelocity -= 386 * (float)gameTime.ElapsedGameTime.TotalSeconds;

            switch ( CollisionSystem.Collide(player, walls, platforms, buttons, door) )
            {
                case CollisionSystem.CollisionResult.GameWon:
                    PublishMessage(new Message(Message.Type.LevelWon));
                    break;
                case CollisionSystem.CollisionResult.PlayerDeath:
                    PublishMessage(new Message(Message.Type.LevelLost));
                    break;
                case CollisionSystem.CollisionResult.ButtonPressed:
                    if (!buttonPushed)
                    {
                        ButtonSound.Play();
                        DoorOpenSound.Play();
                        buttonPushed = true;
                    }
                    break;
                case CollisionSystem.CollisionResult.NoEvents:
                    break;
            }

            if (buttonPushed)
            {
                buttons[0].MoveDown(gameTime);
                door.MoveUp(gameTime);
            }
        }

        public override void Draw(GameTime gameTime)
        {
            DrawChamber();
        }


    }
}
